package com.itheima.web;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.pojo.mongo.Comment;
import com.itheima.servcie.CommentsService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 评论列表
     * @return
     */
    @GetMapping
    private ResponseEntity getComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize, String movementId){
        return ResponseEntity.ok(commentsService.getComments(page, pagesize, movementId));
    }

    /**
     * 发布评论
     * @param comment
     * @return
     */
    @PostMapping
    public ResponseEntity comment(@RequestBody Comment comment){
        commentsService.comment(comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable ObjectId id){
        return ResponseEntity.ok(commentsService.commentLike(id));
    }


    /**
     * 评论取消点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable ObjectId id){
        return ResponseEntity.ok(commentsService.commentDislike(id));
    }
}
